
package org.util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class SqlUtil {
	public  int updateUtil(String sql){
		int i =0;
		try {
			Connection con =CreateDataSource.getDataSource();
			PreparedStatement ps = con.prepareStatement(sql);
			i = ps.executeUpdate();
			
		}catch (SQLException e) {
			e.printStackTrace();
		}catch(Exception e){
			e.printStackTrace();
		}
		return i;
	}
	public  boolean isExist(String sql){
		int i =0;
		try {
			Connection con = CreateDataSource.getDataSource();
			PreparedStatement ps = con.prepareStatement(sql);
			ResultSet eq = ps.executeQuery();
			if(eq.next()){
				i=eq.getInt(1);
			}
			
		}catch (SQLException e) {
			e.printStackTrace();
		}catch(Exception e){
			e.printStackTrace();
		}
		if(i>0){
			return true;
		}else{
			return false;
		}
	}
	
	public ResultSet queryUtil(String sql){
		ResultSet eq =null;
		try {
			Connection con =CreateDataSource.getDataSource(); 
			PreparedStatement ps = con.prepareStatement(sql);
			eq = ps.executeQuery();
		}catch (SQLException e) {
			e.printStackTrace();
		}catch(Exception e){
			e.printStackTrace();
		}
		return eq;
	}
}
